package cn.yunhe.controller;

import cn.yunhe.util.JsonUtil;
import cn.yunhe.util.LoginVeryCodeUtil;


import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@WebServlet("/UserLoginVeryServlet")
public class UserLoginVeryServlet extends HttpServlet {

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String imgname=(int) (new Date().getTime() / 1000) + ".jpg";
        //验证码存放路径
        String imagePath="C:\\Users\\Administrator\\IdeaProjects\\ebuy\\src\\main\\webapp\\VeryCodeImage\\"+imgname;
        Object code=LoginVeryCodeUtil.getVeryCode(imagePath);
        //页面访问路径
        String imagePath1="/VeryCodeImage/"+imgname;
        Map<String,Object> map=new HashMap<>();
        map.put("imagePath",imagePath1);
        map.put("code",code);
        JsonUtil.getJson(resp,map);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doPost( req,resp);
    }
}
